package com.tao.content.api;

import com.tao.base.model.Result;
import com.tao.content.domain.dto.BindTeachplanMediaDto;
import com.tao.content.domain.dto.SaveOrUpdateTeachPlanDto;
import com.tao.content.domain.dto.TeachPlanDetailDto;
import com.tao.content.service.impl.TeachplanMediaServiceImpl;
import com.tao.content.service.impl.TeachplanServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 教学计划接口层
 * </p>
 *
 * @author taohongrun
 * @since 2024/11/4
 */
@RestController
@RequestMapping("/teachPlan")
@Tag(name = "教学计划接口",description = "管理课程教学计划")
@RequiredArgsConstructor
public class TeachPlanController {
    final TeachplanServiceImpl teachplanService;
    final TeachplanMediaServiceImpl teachplanMediaService;
    @GetMapping ()
    @Operation(summary = "查询教学计划",description = "按照树形结构展示详细信息")
    public Result<List<TeachPlanDetailDto>> queryTeachPlan(){
        return Result.success(teachplanService.queryTeachPlan());
    }

    @PostMapping()
    @Operation(summary = "增加或修改教学计划",description = "修改信息较为简单可合并为一个接口")
    public Result saveOrUpdateTeachPlan(@RequestBody SaveOrUpdateTeachPlanDto saveOrUpdateTeachPlanDto){
        teachplanService.saveOrUpdateTeachPlan(saveOrUpdateTeachPlanDto);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除课程计划",description = "根据id删除课程计划")
    @Parameter(name = "id",description = "需要删除的课程计划id",in = ParameterIn.PATH)
    public Result deleteTeachPlan(@PathVariable("id") Long id){
        teachplanService.deleteTeachPlan(id);
        return Result.success();
    }

    @PostMapping("/movedown/{id}")
    @Operation(summary = "下移课程计划",description = "将该课程计划与下一个课程计划交换顺序")
    @Parameter(name = "id",description = "需要移动的课程计划id",in=ParameterIn.PATH )
    public Result movedownTeachPlan(@PathVariable("id") Long id){
        teachplanService.movedownTeachPlan(id);
        return Result.success();
    }

    @PostMapping("/moveup/{id}")
    @Operation(summary = "上移课程计划",description = "将该课程计划与上一个课程计划交换顺序")
    @Parameter(name = "id",description = "需要移动的课程计划id",in=ParameterIn.PATH )
    public Result moveupTeachPlan(@PathVariable("id") Long id){
        teachplanService.moveupTeachPlan(id);
        return Result.success();
    }

    @PostMapping("/teachplan/association")
    @Operation(summary = "绑定视频",description = "绑定课程计划与媒资")
    public Result association(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachplanMediaService.association(bindTeachplanMediaDto);
        return Result.success();
    }
}
